using System;
using System.Diagnostics;

namespace IBNet
{
   /// <summary>
   /// Order Status Event Arguments
   /// </summary>
   [DebuggerDisplay("{OrderStatus}, OrderId: {OrderId}")]
   public class OrderStatusEventArgs : EventArgs
   {
      private readonly OrderStatus orderStatus;
      private readonly int orderId;
      private readonly decimal averageFillPrice;
      private readonly int clientId;
      private readonly int filled;
      private readonly decimal lastFillPrice;
      private readonly int parentId;
      private readonly int permId;
      private readonly int remaining;
      private readonly string whyHeld;

      /// <summary>
      /// Creates a new OrderStatusEventArgs.
      /// </summary>
      /// <param name="orderId">The order Id.</param>
      /// <param name="status">The order status.</param>
      /// <param name="filled">The number of contracts that have been filled.</param>
      /// <param name="remaining">The number of contracts remaining to be filled.</param>
      /// <param name="averageFillPrice">The average price of the shares that have been filled.</param>
      /// <param name="permId">The permanent Id for this order.</param>
      /// <param name="parentId">The parent Id for this order.</param>
      /// <param name="lastFillPrice">The last price of the contracts that have been filled.</param>
      /// <param name="clientId">The client Id that placed this order. ClientId of 0 is also for orders made from TWS.</param>
      /// <param name="whyHeld">String about TWS trying to locate shares for a short sell. The value used to indicate this is "locate".</param>
      public OrderStatusEventArgs(int orderId, OrderStatus status, int filled,
         int remaining, decimal averageFillPrice, int permId, int parentId,
         decimal lastFillPrice, int clientId, string whyHeld)
      {
         this.orderId = orderId;
         this.clientId = clientId;
         this.lastFillPrice = lastFillPrice;
         this.parentId = parentId;
         this.permId = permId;
         this.averageFillPrice = averageFillPrice;
         this.remaining = remaining;
         this.filled = filled;
         this.orderStatus = status;
         this.whyHeld = whyHeld;
      }

      /// <summary>
      /// Gets the order Id.
      /// </summary>
      public int OrderId
      {
         get { return orderId; }
      }

      /// <summary>
      /// Gets the OrderStatus.
      /// </summary>
      public OrderStatus OrderStatus
      {
         get { return orderStatus; }
      }

      /// <summary>
      /// Gets the number of contracts filled.
      /// </summary>
      public int Filled
      {
         get { return filled; }
      }

      /// <summary>
      /// Gets the number of contracts remaining to be filled.
      /// </summary>
      public int Remaining
      {
         get { return remaining; }
      }

      /// <summary>
      /// Gets the average price of the contracts that have been filled.
      /// </summary>
      public decimal AverageFillPrice
      {
         get { return averageFillPrice; }
      }

      /// <summary>
      /// Gets the permanent Id for this order.
      /// </summary>
      public int PermId
      {
         get { return permId; }
      }

      /// <summary>
      /// Gets the parent Id for this order.
      /// </summary>
      public int ParentId
      {
         get { return parentId; }
      }

      /// <summary>
      /// Gets the last fill price for contracts that have been filled.
      /// </summary>
      public decimal LastFillPrice
      {
         get { return lastFillPrice; }
      }

      /// <summary>
      /// Gets the client Id that placed this order. 
      /// ClientId of 0 is also for orders made from TWS.
      /// </summary>
      public int ClientId
      {
         get { return clientId; }
      }

      /// <summary>
      /// Gets a string about TWS trying to locate shares for a short sell. 
      /// The value used to indicate this is "locate".
      /// </summary>
      public string WhyHeld
      {
         get { return whyHeld; }
      }

      public override string ToString()
      {
         string representation = "OrderStatusEventArgs: OrderStatus: " + orderStatus +
            ", OrderId: " + orderId + ", AverageFillPrice: " + averageFillPrice +
            ", ClientId: " + clientId + ", Filled: " + filled + ", LastFillPrice: " +
            lastFillPrice + ", ParentId: " + parentId + ", PermId: " + permId +
            ", Remaining: " + remaining + ", WhyHeld: " + whyHeld;
         return representation;
      }
   }
}